package cn.kgc.base.service.impl;

import cn.kgc.base.entity.SysDictItem;
import cn.kgc.base.mapper.SysDictItemMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.base.mapper.SysDictMapper;
import cn.kgc.base.entity.SysDict;
import cn.kgc.base.service.SysDictService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.stylesheets.LinkStyle;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * (SysDict)表服务实现类
 *
 * @author makejava
 * @since 2022-11-30 14:32:53
 */
@Service("sysDictService")
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {
    @Resource
    private SysDictItemMapper sysDictItemMapper;
    @Resource
    private SysDictMapper sysDictMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    public boolean deleteById(String id) {
        LambdaQueryWrapper<SysDictItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysDictItem::getDictId, id);
        sysDictItemMapper.delete(queryWrapper);
       /* List<SysDictItem> sysDictItems = sysDictItemMapper.selectList(queryWrapper);
        if (sysDictItems.size() > 0) {
            for (SysDictItem sysDictItem : sysDictItems) {
                sysDictItemMapper.deleteById(sysDictItem);
            }
        }*/
        sysDictMapper.deleteById(id);
        return true;
    }
}
